<template>
    <h2 align="center">管理员登录</h2>
    <table border="1" align="center">
        <tr>
            <td>管理员账号</td>
            <td>
                <input type="text" v-model="state.name">
            </td>
        </tr>
        <tr>
            <td>管理员的密码</td>
            <td>
                <input type="password" v-model="state.pwd" >
            </td>
        </tr>
        <tr>
            <td></td>
            <td>
                <input type="button" value="登录" @click="minlogin" >
            </td>
        </tr>
    </table>
</template>
<script setup lang="ts">
import { reactive,toRefs } from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';
const router = useRouter();
import {useUseStore} from '../store/user';
const userStore = useUseStore();
const data=reactive({
    state:{
        name:'',
        pwd:''
    }
})
const {state} =toRefs(data);
//登录成功存取数据
//Pinia方法
const minlogin=()=>{
    axios({
        url:'/api/MemberLogin/MinLogin',
        method:'post',
        params:state.value
    })
    .then(res=>{
        console.log(res);
        if(res.data.data!=""){
            alert('登录成功')
            userStore.userinfo=res.data.data
            router.push('/views/member')
        }else{
            alert('登录失败')
        }
    })
    .catch(err=>{
        console.log(err);
    })
}
</script>